﻿namespace Singer.Extensions.Excel;

/// <summary>
/// Excel导出模型
/// </summary>
public class ExportExcelModel
{
    /// <summary>
    /// 文件名
    /// </summary>
    public string FileName { get; set; }
    /// <summary>
    /// 表格名
    /// </summary>
    public string SheetName { get; set; } = "Sheet1";
    /// <summary>
    /// 导出保存的路径
    /// </summary>
    public string SavePath { get; set; }
    /// <summary>
    /// excel类型
    /// </summary>
    public ExcelSuffix ExcelSuffix { get; set; }
    /// <summary>
    /// 大标题
    /// </summary>
    public string Title { get; set; }

    public IEnumerable<ExcelColum> ExcelColums { get; set; } = new ExcelColum[0];

    public string FilePath => $"{SavePath.TrimEnd(new char[] { '/', '\\' })}/" +
            $"{FileName.TrimStart(new char[] { '/', '\\' })}.{ExcelSuffix}";
}

/// <summary>
/// Excel的列模型
/// </summary>
public class ExcelColum
{
    /// <summary>
    /// 字段名
    /// </summary>
    public string Name { get; set; }
    /// <summary>
    /// 导出的字段标题
    /// </summary>
    public string Title { get; set; }
    /// <summary>
    /// 是否忽略
    /// </summary>
    public bool Ignore { get; set; }

    public ExcelColum(string name, string title = "", bool ignore = false)
    {
        if (string.IsNullOrWhiteSpace(name))
            throw new ArgumentNullException(nameof(name));
        Name = name;
        Title = (string.IsNullOrWhiteSpace(title) ? name : title) ?? "";
        Ignore = ignore;
    }
}

/// <summary>
/// excel文件拓展名
/// </summary>
public enum ExcelSuffix
{
    /// <summary>
    /// .xlsx
    /// </summary>
    xlsx,
    /// <summary>
    /// .xls
    /// </summary>
    xls
}
